
import 'package:flutter/cupertino.dart';
import 'package:flutter_easyloading/flutter_easyloading.dart';
import 'package:get/get.dart';

import '../../request/api.dart';
import '../../request/requestManager.dart';

class ReportController extends GetxController {

  int type = 1; //举报类型 1 个人详情页 2 视频结束 3 动态 4.IM页面
  int reportUid = 0; //举报的用户ID
  List<Map> reportList = [];
  int index = -1;
  TextEditingController reasonController = TextEditingController();
  @override
  void onInit() {
    super.onInit();
    type = int.parse(Get.parameters['type'].toString());
    reportUid = int.parse(Get.parameters['reportUid'].toString());
    getReportCateList();
  }


  void getReportCateList() async {
    var result = await RequestManager().post(API.reportCateList);
    if (result != null && result['code'] == 0) {
      List tempList = result['data'];
      for (var element in tempList) {
        reportList.add(element);
      }
      update();
    }
  }

  void reportItemClick(int selectIndex) {
    index = selectIndex;
    update();
  }

  void submitReport() async {
    if (index == - 1) return;
    Map params = {
      'cate_id':reportList[index]['id'],
      'type':type,
      'report_uid':reportUid
    };
    if (reasonController.text.isNotEmpty) {
      params['content'] = reasonController.text;
    }
    var result = await RequestManager().post(API.submitReport,params: params);
    if (result != null && result['code'] == 0) {
      EasyLoading.showToast(result['message']);
      Get.back();
    }
  }
}